//
//
// *  $Id: TestPhysicalRowIdManager.java,v 1.5 2003/09/21 15:49:02 boisvert Exp $
//
// *
//
// *  Unit tests for PhysicalRowIdManager class
//
// *
//
// *  Simple db toolkit
//
// *  Copyright (C) 1999, 2000 Cees de Groot <cg@cdegroot.com>
//
// *
//
// *  This library is free software; you can redistribute it and/or
//
// *  modify it under the terms of the GNU Library General Public License
//
// *  as published by the Free Software Foundation; either version 2
//
// *  of the License, or (at your option) any later version.
//
// *
//
// *  This library is distributed in the hope that it will be useful,
//
// *  but WITHOUT ANY WARRANTY; without even the implied warranty of
//
// *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//
// *  Library General Public License for more details.
//
// *
//
// *  You should have received a copy of the GNU Library General Public License
//
// *  along with this library; if not, write to the Free Software Foundation,
//
// *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
//
// 

//*************************************************************************
//**  Included in JDMB 1.0 port to SharpDBM;  11/2013 Cyrus Neah cneah@codingreal.com
//**  SharpDBM is an independent reimplementation of the JDBM 1.0 software library  
//*************************************************************************

using SharpDBM;
using SharpDBM.recman;
using SharpDBM.helper;
using SharpDBM.btree;
using NUnit.Framework;



namespace SharpDBM.Test

.recman
{

	using NUnit.Framework;


///
//
// *  This class contains all Unit tests for {@link PhysicalRowIdManager}.
//
// 

	[TestFixture]
    public class TestPhysicalRowIdManager  
	{



		



		[Test]
 public virtual void setUp()
		{

			TestRecordFile.deleteTestFile();

		}



		[Test]
 public virtual void tearDown()
		{

			TestRecordFile.deleteTestFile();

		}



//    *
//
//     *  Test constructor
//
//     

 
//
		[Test]
 public virtual void testCtor()
		{

			RecordFile f = new RecordFile(TestRecordFile.testFileName);

			PageManager pm = new PageManager(f);

			PhysicalRowIdManager physMgr = new PhysicalRowIdManager(f, pm);



			f.forceClose();

		}



//    *
//
//     *  Test basics
//
//     

 
//
		[Test]
 public virtual void testBasics()
		{



			RecordFile f = new RecordFile(TestRecordFile.testFileName);

			PageManager pm = new PageManager(f);

			PhysicalRowIdManager physMgr = new PhysicalRowIdManager(f, pm);



		// insert a 10,000 byte record.

			sbyte[] data = TestUtil.makeRecord(10000, (sbyte) 1);

			Location loc = physMgr.insert(data, 0, data.Length);

            NUnit.Framework.Assert.IsTrue(TestUtil.checkRecord(physMgr.fetch(loc), 10000, (sbyte)1), "check data1");



		// update it as a 20,000 byte record.

			data = TestUtil.makeRecord(20000, (sbyte) 2);

			Location loc2 = physMgr.update(loc, data, 0, data.Length);

            NUnit.Framework.Assert.IsTrue(TestUtil.checkRecord(physMgr.fetch(loc2), 20000, (sbyte)2), "check data2");



		// insert a third record. This'll effectively block the first one

		// from growing

			data = TestUtil.makeRecord(20, (sbyte) 3);

			Location loc3 = physMgr.insert(data, 0, data.Length);

            NUnit.Framework.Assert.IsTrue(TestUtil.checkRecord(physMgr.fetch(loc3), 20, (sbyte)3), "check data3");



		// now, grow the first record again

			data = TestUtil.makeRecord(30000, (sbyte) 4);

			loc2 = physMgr.update(loc2, data, 0, data.Length);

            NUnit.Framework.Assert.IsTrue(TestUtil.checkRecord(physMgr.fetch(loc2), 30000, (sbyte)4), "check data4");





		// delete the record

			physMgr.delete(loc2);



			f.forceClose();

		}



//    *
//
//     *  Runs all tests in this class
//
//     

		static void Main(string[] args)
		{

			// junit.textui.TestRunner.run(new TestSuite(typeof(TestPhysicalRowIdManager)));

		}

	}


}